using System;
using System.Web.Mvc;
using System.Collections.Generic;
using TjingMe.Web.Models;
using System.Linq;

namespace TjingMe.Web.Controllers
{
	public class EventController : Controller
	{
		public ActionResult Create(){
			return View ("Create",new Event{Name="apa", Key = EventRepository.CreateKey()});
		}
		
		[HttpPost]
		public ActionResult Create(Event model){
			if(ModelState.IsValid){
				repository.Save(model);

				return RedirectToAction("ShowList",new {@id = model.Key});
			}
			return Json(ModelState);
		}
		
		public ActionResult Edit(string id){
			return View("Edit",repository.GetEvent(id));
		}
		
		public ActionResult ShowList(string id){
			var ev = repository.GetEvent(id);
			return View("ShowList",ev);
		}
		
		public ActionResult ShowItemsList(string id){
			
			return View (repository.GetEvent(id).ItemLists[0]);
		}
		
		public EventRepository repository {
			get{
				return new EventRepository();
			}
		}
	}
}

